package com.example.demo.config.artemis;

import org.apache.activemq.artemis.api.core.client.ClientConsumer;
import org.apache.activemq.artemis.api.core.client.ClientProducer;
import org.apache.activemq.artemis.api.core.client.ClientSession;

import java.util.Date;

public class ConsumerTest {
    public static void main(String[] args) throws InterruptedException {
        ActiveMqManager.initClientSessionFactory();
        for(int j = 0; j < 5; j++) {
            Thread.sleep(10);
            final ClientSession session = ActiveMqManager.createClientSession(ActiveMqManager.PROTO_TCP, Boolean.TRUE);
            //ActiveMqManager.createQueue(session, ActiveMqManager.RDO_QUEUE_TCP + j);
            ClientConsumer consumer = ActiveMqManager.createNewConsumer(session, ActiveMqManager.RDO_QUEUE_TCP+ j);
            new Thread(() -> {
                for (int i = 0; i < 10000; i++) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                    }
                    String msg = ActiveMqManager.getMessage(consumer);
                    System.out.println(Thread.currentThread().getName()  + "-" + i + "->" + msg);
                }
                ActiveMqManager.closeSession(session);
            }, "CONSUMER-" + j).start();
        }
    }
}
